﻿create PROCEDURE Sync.SP_CommitteeBankAccountDepositAttachments_SelectChanges
@LastRowVersion rowversion,
@FilterdColumn UNIQUEIDENTIFIER
AS 
BEGIN 
	SELECT 
        t.[CommitteeBankAccountDepositAttachmentID],
		g.[CommitteeBankAccountDepositID],g.[Attachment],
		t.IsDeleted,
		t.LastUpdatedDate
	FROM [dbo].[CommitteeBankAccountDepositAttachments] g RIGHT JOIN Sync.CommitteeBankAccountDepositAttachments_Tracking t  
    ON t.CommitteeBankAccountDepositAttachmentID = g.CommitteeBankAccountDepositAttachmentID 
    join CommitteeBankAccountDeposites on 
	g.CommitteeBankAccountDepositID = CommitteeBankAccountDeposites.CommitteeBankAccountDepositID
	join CommitteeBankAccount on CommitteeBankAccount.CommitteeBankAccountID = CommitteeBankAccountDeposites.CommitteeBankAccountID
	WHERE (@LastRowVersion IS NULL OR t.Version > @LastRowVersion)
	AND ((@FilterdColumn IS NULL) OR (CommitteeBankAccount.CommitteeID = @FilterdColumn))
    END











